package de.openkanban.client.ui.presenter;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;

import de.openkanban.client.login.LogIn;
import de.openkanban.client.ui.adminpanel.UserAccountAvatarForm;
import de.openkanban.client.util.RootPanel;
import de.openkanban.shared.dto.UserDto;

/**
 * Callback that handles get user account request
 */
public class GetUserAccountRequestCallback implements RequestCallback {

	private UserAccountAvatarForm userAccountAvatarForm;

	public GetUserAccountRequestCallback(UserAccountAvatarForm userAccountAvatarForm) {
		this.userAccountAvatarForm = userAccountAvatarForm;
	}

	@Override
	public void onResponseReceived(Request request, Response response) {
		UserDto userDto = new UserDto(response.getText());
		LogIn.setUserDto(userDto);

		userAccountAvatarForm.updateAvatar();
		RootPanel.main.getFooter().updateBoardContactData();
		RootPanel.main.getFooter().updateUserContactsData();
	}

	@Override
	public void onError(Request request, Throwable exception) {

	}

}
